// callHsEvent.c -- generate events for hellosoft voip stack

#include <stdio.h>
#include <debuglog.h>
#include <config.h>
#include <eventlog.h>
#include <avmerrCode.h>

#include <hs_voip_sys.h>
#include <hs_voip_dim_control.h>
#include <hs_voip_ccm_app_if.h>
#include <hs_voip_oam_cli_if.h>
#include <hs_voip_mc_global.h>
#include <callCtrl.h>
#include <callHsEvent.h>
#include <callCtrlEventLog.h>




avmerrCode callHsReleaseErrorToAvmErr(
        enum hs_voip_release_call_reason_code reason,
        int Verbose
        )
{
    avmerrCode err = 0;
    /* Special handling for a few "errors" */
    switch ( reason ) {
        case HS_VOIP_RELEASE_NORMAL:       /* Normal release by remote end */
            if ( Verbose ) 
                debugf("Call terminated with HS_VOIP_RELEASE_NORMAL\n");
        return 0;
        case HS_VOIP_RELEASE_USER_CANCEL:  /* User cancelled the call */
            if ( Verbose )
                debugf("Call terminated with HS_VOIP_RELEASE_USER_CANCEL\n");
        return 0;
        default:
        break;
    }
    /* Handle all other errors generically.
     * There is no elegant way to do this without possibly losing any
     * additions.
     * The following must agree with 
     * enum hs_voip_release_call_reason_code reason
     * in hs/ccm/include/hs_voip_ccm_app_if.h
     * which in turn must agree with enum hs_sip326x_if_response_code
     * in hs/tu/include/hs_sip326x_if.h ...
     * ... see hs_voip_ccm_send_app_release_ind() to understand why!
     */
    if ( reason >= 0x1000 && reason < 0x1100 ) {
        /* Beginning with HS_VOIP_RELEASE_ERROR and largely consisting
         * of remote call termination codes
         */
       if ( Verbose ) debugf(
           "Call terminated with hs_voip_release_call_reason_code 0x%x = "
           "hs_sip326x_if_response_code %d", reason, reason - 0x1000 );
        err = avmerrCodeMake(avmerrComponent_HelloSoft,
            amverrHelloSoft_RemoteCallRelease, 
            reason - 0x1000);
    } else 
    if ( reason >= 0x2000 && reason < 0x2100 ) {
       if ( Verbose ) debugf(
           "Call terminated with hs_voip_release_call_reason_code 0x%x = "
            "local code %d", reason, reason - 0x2000 );
        /* Beginning with HS_VOIP_RELEASE_NOMORE_NEW_CALLS_ON_EP and
         * consisting of local call termination codes
         */
        err = avmerrCodeMake(avmerrComponent_HelloSoft,
            amverrHelloSoft_LocalCallRelease, 
            reason - 0x2000);
    } else
    {
        /* Catch all in case of (unknown) error return not matching
         * above 
         */
       if ( Verbose ) debugf(
           "Call terminated with hs_voip_release_call_reason_code 0x%x = "
           "unknown", reason);
        err = avmerrCodeMake(avmerrComponent_HelloSoft,
            amverrHelloSoft_MiscCallRelease, 
            reason );
    }
    return err;
}


avmerrCode callHsRegisterErrorToAvmErr(
        enum hs_voip_sip_regster_resp_code code,
        int Verbose
        )
{
    // See enum hs_voip_sip_regster_resp_code
    // in hs/ccm/include/hs_voip_ccm_app_if.h !
    if ( code == HS_VOIP_SIP_REGISTER_SUCCESS ) {
        if ( Verbose ) debugf( "Registration success!");
        return 0;
    }
    avmerrCode err = avmerrCodeMake( avmerrComponent_HelloSoft,
        amverrHelloSoft_Registration,
        code - 2000 );
    if ( Verbose ) debugf("Registration err 0x%x (raw code %d, reg err %d)",
        err, code, code-2000 );
    return err;
}

avmerrCode callHsSubscribeMwiErrorToAvmErr(
        enum hs_sip326x_if_response_code code,
        int Verbose
        )
{
    if (( code == HS_SIP326X_RESP_SUCCESS ) ||
        ( code == HS_SIP326X_RESP_NORMAL ) ||
        ( code == HS_SIP326X_IF_RESP_ACCEPTED )) {
        if ( Verbose ) debugf( "SubscribeMwi success!");
        return 0;
    }
    avmerrCode err = avmerrCodeMake( avmerrComponent_HelloSoft,
        amverrHelloSoft_SubscribeMwi,
        code);
    if ( Verbose ) debugf("SubscribeMwi err 0x%x (raw code %d, sub err %d)",
        err, code, code);
    return err;
}


// TODO: make sure that hs code can handle same no. (or more) endpoints
// as callCtrl.c ...

//
//  From hellosoft version 2 (2.5):
//  typedef enum hs_voip_app_event_type
//  {
//     HS_VOIP_INCOMING_CALL_IND,    /* Incoming call indication */
//     HS_VOIP_CALL_INITIATED_IND,   /* Outgoing call initiated */
//     HS_VOIP_RINGING_IND,          /* UA ringing at remote end */
//     HS_VOIP_ANSWER_IND,           /* Call answered at remote end */
//     HS_VOIP_HOLD_CALL_IND,        /* Call held indication */
//     HS_VOIP_HOLD_CALL_RESP,       /* Response for Call hold request */
//     HS_VOIP_UNHOLD_CALL_IND,      /* Call unheld indication */
//     HS_VOIP_UNHOLD_CALL_RESP,     /* Response for Call unhold request */
//     HS_VOIP_TRANSFER_CALL_IND,    /* Call transferred indication */
//     HS_VOIP_TRANSFER_CALL_RESP,   /* Response for call transfer request */
//     HS_VOIP_TRANSFER_CALL_REQ_IND,/* Request to transfer current call by remote end */
//     HS_VOIP_CHANGE_CODEC_IND,     /* Codec change indication */
//     HS_VOIP_CHANGE_CODEC_RESP,    /* Response to codec change request */
//     HS_VOIP_CONF_STARTED_IND,     /* Conference started indication */
//     HS_VOIP_CALL_EXIT_CONF_IND,   /* UA exited conference */
//     HS_VOIP_RELEASE_CALL_IND,     /* Call release */
//     HS_VOIP_INVALID_REQUEST_IND,  /* Invalid request from Application */
//     HS_VOIP_SIP_REGISTER_RESP,    /* Response for SIP register */
//     HS_VOIP_CRITICAL_ERROR_IND,   /* Crictal error */
//     HS_VOIP_IM_MSG_RECVD_IND,     /* Instant message received */
//     HS_VOIP_IM_MSG_RESP_IND,      /* Response for sent instant message */
//     HS_VOIP_CALL_FORWARDED_TO_IND,/* Call being forwarded to other UA */
//     HS_VOIP_SWITCH_CALL_IND,      /* Call switch done */
//     HS_VOIP_SUBSCPT_RCVD_IND,     /* Subscription msg received */
//     HS_VOIP_SUBSCPT_RESP_RCVD_IND,/* Response for subscription request */
//     HS_VOIP_SUBSCPT_SENT_IND,     /* Subscription message sent */
//     HS_VOIP_NOTIFY_RCVD_IND,      /* Notify message received */
//     HS_VOIP_NOTIFY_TERM_IND,/* Terminal Notify received (subscription terminated)*/
//     HS_VOIP_MSG_WAIT_IND,         /* Message waiting */
//     HS_VOIP_OUTGOING_CALL_REJECTED_IND,/* Outgoing call screened/rejected */
//     HS_VOIP_INCOMING_CALL_REJECTED_IND,/* Incoming call screened/rejected */
//     HS_VOIP_INFO_REQ_RECVD_IND,   /* INFO request received */
//     HS_VOIP_INFO_RESP,            /* Response for INFO request */
//     HS_VOIP_SERVICE_INFO_SENT_IND,/* Service message sent */
//     HS_VOIP_SERVICE_REQUEST_IND,  /* Service request received */
//     HS_VOIP_SERVICE_RESPONSE_IND, /* Response for service received */   
//     HS_VOIP_CALL_FORWARD_REQ_IND, /* Request to forward current call, by remote end */
//     HS_VOIP_INCOMING_CALL_REDIRECTED_IND,/* Incoming call being redirected to other UA */
//     HS_VOIP_REQ_RETRY_RCVD_IND,/* Request retry response received */
//     HS_VOIP_MWI_SUBSCB_RESP_IND   /* Response for MWI subscription */
//  } hs_voip_app_event_type_t;

void callHsEventHandler( hs_voip_app_event_msg_t *msg )
{
    // Note: callId's are arbitrary unsigned nos. except ~0 indicates invalid.
    unsigned callId = (int) msg->call_id;
    hs_voip_app_event_type_t eventType = msg->event_type;
    switch ( eventType )
    {
        case HS_VOIP_INCOMING_CALL_IND :
        {
            callHsEventLog(" HS_VOIP_INCOMING_CALL_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_INCOMING_CALL_IND\n", callId );
            hs_voip_incoming_call_ind_t *data =
                &msg->event_info.incoming_call_ind;
            // typedef struct hs_voip_identity
            // {
            //    hs_char uri[HS_VOIP_SIP_URL_SIZE];
            //    hs_char display_name[HS_VOIP_SIP_DISPLAY_NAME_SIZE];
            // } hs_voip_identity_t;
            // typedef struct hs_voip_incoming_call_ind
            // {
            //    hs_voip_identity_t     caller;
            //    hs_voip_identity_t     callee;
            //    hs_uint32              replaces_callid; 
            // } hs_voip_incoming_call_ind_t;
            char *caller = data->caller.uri;
            char *displayName = data->caller.display_name;
            if ( ! caller[0] ) {
                caller = data->caller.display_name;
            }
            /* CK, check the replaces_callid to replace the current call, for call transfer */
            if(data->replaces_callid != HS_VOIP_UNALLOCATED_CALL_ID)
            {
                callCtrlReplaceCall(
                    caller, displayName, data->replaces_callid, callId);
            }
            else
            {
                if(callCtrlIsMvqMode())
                {
                    printf("====>Call coming from %s...\n", displayName); 
                }
                callCtrlNewInboundCall(caller, displayName, callId);
            }
            //(void) data;
        }
        break;
        case HS_VOIP_CALL_INITIATED_IND :
        {
            callHsEventLog(" HS_VOIP_CALL_INITIATED_IND");
            /* async response to hs_voip_make_call 
             * This just means that the stack has accepted the call.
             */
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_CALL_INITIATED_IND\n", callId );
            hs_voip_call_initiated_ind_t *data = 
                &msg->event_info.call_initiated_ind;
            callCtrlOutboundCallAccepted(callId);
            (void) data;
        }
        break;
        case HS_VOIP_RINGING_IND :
        {
            callHsEventLog(" HS_VOIP_RINGING_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_RINGING_IND\n", callId );
            callCtrlOutboundCallRinging(callId);
            /* no event data */
        }
        break;
        case HS_VOIP_ANSWER_IND :
        {
            callHsEventLog(" HS_VOIP_ANSWER_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_ANSWER_IND\n", callId );
            /* no event data */
            callCtrlOutboundCallAnswered(callId);
        }
        break;
        case HS_VOIP_HOLD_CALL_IND :
        {
            callHsEventLog(" HS_VOIP_HOLD_CALL_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_HOLD_CALL_IND\n", callId );
/*
            hs_voip_hold_call_ind_t *data = &msg->event_info.hold_ind;
            hs_voip_call_held_mode_t mode = data->mode;
            callCtrlStackHoldLocal( callId,
                mode == HS_VOIP_HELD_LOCAL || mode == HS_VOIP_HELD_BOTH);
            callCtrlStackHoldRemote( callId,
                mode == HS_VOIP_HELD_REMOTE || mode == HS_VOIP_HELD_BOTH);
*/
            callCtrlStackHoldRemote( callId, 1);
        }
        break;
        case HS_VOIP_HOLD_CALL_RESP :
        {
            callHsEventLog(" HS_VOIP_HOLD_CALL_RESP");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_HOLD_CALL_RESP\n", callId );
            hs_voip_hold_call_resp_t *data = &msg->event_info.hold_resp;
            int response_code = data->response_code;
            if ( response_code ) {
                debugf("callHsEventHandler ERROR %d doing hold\n", 
                    response_code );
            }
/*
            hs_voip_call_held_mode_t mode = data->mode;
            callCtrlStackHoldLocal( callId,
                mode == HS_VOIP_HELD_LOCAL || mode == HS_VOIP_HELD_BOTH);
            callCtrlStackHoldRemote( callId,
                mode == HS_VOIP_HELD_REMOTE || mode == HS_VOIP_HELD_BOTH);
*/
            callCtrlStackHoldLocal( callId, 1);
        }
        break;
        case HS_VOIP_UNHOLD_CALL_IND :
        {
            callHsEventLog(" HS_VOIP_UNHOLD_CALL_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_UNHOLD_CALL_IND\n", callId );
/*
            hs_voip_hold_call_ind_t *data = &msg->event_info.unhold_ind;
            hs_voip_call_held_mode_t mode = data->mode;
            callCtrlStackHoldLocal( callId,
                mode == HS_VOIP_HELD_LOCAL || mode == HS_VOIP_HELD_BOTH);
            callCtrlStackHoldRemote( callId,
                mode == HS_VOIP_HELD_REMOTE || mode == HS_VOIP_HELD_BOTH);
*/
            callCtrlStackHoldRemote( callId, 0);
        }
        break;
        case HS_VOIP_UNHOLD_CALL_RESP :
        {
            callHsEventLog(" HS_VOIP_UNHOLD_CALL_RESP");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_UNHOLD_CALL_RESP\n", callId );
/*
            hs_voip_unhold_call_resp_t *data = &msg->event_info.unhold_resp;
            hs_voip_call_held_mode_t mode = data->mode;
            callCtrlStackHoldLocal( callId,
                mode == HS_VOIP_HELD_LOCAL || mode == HS_VOIP_HELD_BOTH);
            callCtrlStackHoldRemote( callId,
                mode == HS_VOIP_HELD_REMOTE || mode == HS_VOIP_HELD_BOTH);
*/
            callCtrlStackHoldLocal( callId, 0);
        }
        break;
        case HS_VOIP_TRANSFER_CALL_IND :
        {
            callHsEventLog(" HS_VOIP_TRANSFER_CALL_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_TRANSFER_CALL_IND\n", callId );
            debugf("callHsEventHandler: New stack id %x uri:%s display_name:%s\n",
                   msg->event_info.transfer_ind.new_call_id,
                   msg->event_info.transfer_ind.target.uri,
                   msg->event_info.transfer_ind.target.display_name);
            /* the current call is transfered to another party */
            callCtrlStackCallTransfered(callId,
                msg->event_info.transfer_ind.new_call_id,
                msg->event_info.transfer_ind.target.uri,
                msg->event_info.transfer_ind.target.display_name);
        }
        break;
        case HS_VOIP_TRANSFER_CALL_RESP :
        {
            callHsEventLog(" HS_VOIP_TRANSFER_CALL_RESP");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_TRANSFER_CALL_RESP\n", callId );
            int response_code = msg->event_info.transfer_resp.response_code;
            callCtrlTransferDone(callId, response_code);
        }
        break;
        case HS_VOIP_TRANSFER_CALL_REQ_IND: 
        /* Request to transfer current call by remote end */
        {
            callHsEventLog(" HS_VOIP_TRANSFER_CALL_REQ_IND ");
        }
        break;
        case HS_VOIP_CHANGE_CODEC_IND:     /* Codec change indication */
        {
            callHsEventLog(" HS_VOIP_CHANGE_CODEC_IND ");
        }
        break;
        case HS_VOIP_CHANGE_CODEC_RESP :
        {
            callHsEventLog(" HS_VOIP_CHANGE_CODEC_RESP");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_CHANGE_CODEC_RESP\n", callId );
            hs_voip_change_codec_resp_t *data = 
                &msg->event_info.change_codec_resp;
            (void) data;
        }
        break;
        case HS_VOIP_CONF_STARTED_IND :
        /* Conference started indication */
        {
            callHsEventLog(" HS_VOIP_CONF_STARTED_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_CONF_STARTED_IND\n", callId );
            callCtrlConferenceStarted();
        }
        break;
        case HS_VOIP_CALL_EXIT_CONF_IND:   /* UA exited conference */
        {
            callHsEventLog(" HS_VOIP_CALL_EXIT_CONF_IND ");
        }
        break;
        case HS_VOIP_RELEASE_CALL_IND :
        {
            callHsEventLog(" HS_VOIP_RELEASE_CALL_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_RELEASE_CALL_IND\n", callId );
            hs_voip_release_call_ind_t *data = &msg->event_info.release_ind;
            avmerrCode err = callHsReleaseErrorToAvmErr(
                data->reason_code, 1/*verbose*/ );
            debugf("... err 0x%x reason_code %d reason_phrase %s\n", 
                err, data->reason_code, data->reason_phrase );
            callCtrlCallRejected(callId, err);

        }
        break;
        case HS_VOIP_INVALID_REQUEST_IND :
        {
            callHsEventLog(" HS_VOIP_INVALID_REQUEST_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_INVALID_REQUEST_IND\n", callId );
            hs_voip_invalid_request_ind_t *data = 
                &msg->event_info.invalid_request_ind;
            (void) data;
        }
        break;
        case HS_VOIP_SIP_REGISTER_RESP :
        {
            callHsEventLog(" HS_VOIP_SIP_REGISTER_RESP");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_SIP_REGISTER_RESP\n", callId );
            hs_voip_sip_register_resp_t *data = &msg->event_info.sip_reg_resp;
            // typedef struct hs_voip_sip_register_resp
            // {
            // hs_voip_sip_register_resp_code_t   reason_code;
            // hs_char                            reason_phrase[HS_VOIP_REASON_PHRASE_SIZE];
            // hs_voip_identity_t                 caller;
            // #if 1 /* ventoux */
            // hs_uint32 expireTime;
            // #endif 
            // } hs_voip_sip_register_resp_t;
            //    HS_VOIP_SIP_REGISTER_SUCCESS = 2000, /* successful */
            //    HS_VOIP_SIP_REGISTER_PREV_PENDING,   /* Previous request pending */
            //    HS_VOIP_SIP_REGISTER_TIMEOUT,        /* request timed out */
            //    HS_VOIP_SIP_REGISTER_ADDR_ERROR,     /* Invalid registrar address */
            //    HS_VOIP_SIP_REGISTER_ERROR           /* Any other error */
            //    
            debugf("... reason_code %d reason=%s uri=%s",
                data->reason_code, data->reason_phrase, data->caller.uri );
            avmerrCode err = callHsRegisterErrorToAvmErr(
                data->reason_code, 1/*verbose*/ );
            callCtrlRegistrationHandler( err, data->expireTime );
        }
        break;
        case HS_VOIP_CRITICAL_ERROR_IND :
        {
            callHsEventLog(" HS_VOIP_CRITICAL_ERROR_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_CRITICAL_ERROR_IND\n", callId );
            /* no event data */
        }
        break;
        case    HS_VOIP_IM_MSG_RECVD_IND:     /* Instant message received */
        {
            callHsEventLog(" HS_VOIP_IM_MSG_RECVD_IND ");
			//call callCtrlXXX to save it
			//by Mike
			callCtrlReceiveIM(
				msg->event_info.im_msg_recvd_ind.caller.uri,
				msg->event_info.im_msg_recvd_ind.im_msg
			);
        }
        break;
        case HS_VOIP_IM_MSG_RESP_IND:  /* Response for sent instant message */
        {
            callHsEventLog(" HS_VOIP_IM_MSG_RESP_IND ");
        }
        break;
        case HS_VOIP_CALL_FORWARDED_TO_IND: /* Call being forwarded to other UA */
        {
            callHsEventLog(" HS_VOIP_CALL_FORWARDED_TO_IND ");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_CALL_FORWARDED_TO_IND\n", callId );
            debugf("callHsEventHandler: Forward to uri:%s, display_name:%s\n",
                msg->event_info.call_forwarded_ind.forwarded_to_str.uri,
                msg->event_info.call_forwarded_ind.forwarded_to_str.display_name);
            callCtrlStackForwardCall( callId, 
                msg->event_info.call_forwarded_ind.forwarded_to_str.uri, 
                msg->event_info.call_forwarded_ind.forwarded_to_str.display_name);
        }
        break;
        case HS_VOIP_SWITCH_CALL_IND:      /* Call switch done */
        {
            callHsEventLog(" HS_VOIP_SWITCH_CALL_IND ");
        }
        break;
        case HS_VOIP_SUBSCPT_RCVD_IND:     /* Subscription msg received */
        {
            callHsEventLog(" HS_VOIP_SUBSCPT_RCVD_IND ");
        }
        break;
        case HS_VOIP_SUBSCPT_RESP_RCVD_IND: 
        /* Response for message waiting indicator subscription request */
        {
            //typedef struct hs_voip_app_subscb_resp_ind
            //{
            //   /* specifies the subscription identity */
            //   hs_uint32    sub_id;
            //   /* subcription duration requested for the event */
            //   hs_uint32    expires;
            //   hs_uint32    reason_code; 
            //   hs_char      reason_phrase[HS_VOIP_REASON_PHRASE_SIZE];
            //} hs_voip_app_subscb_resp_ind_t, hs_voip_app_subscp_resp_t;
            callHsEventLog(" HS_VOIP_SUBSCPT_RESP_RCVD_IND ");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_SUBSCPT_RESP_RCVD_IND\n", callId );
            hs_voip_app_subscp_resp_t *data = &msg->event_info.subscb_resp_ind;
            avmerrCode err = callHsSubscribeMwiErrorToAvmErr(
                data->reason_code, 1/*Verbose*/ );
            debugf("... err 0x%x reason %d = %s expires %d sec.",
                err, data->reason_code, data->reason_phrase, data->expires );
            callCtrlSubscribeMwiHandler(err, data->expires);
        }
        break;
        case HS_VOIP_SUBSCPT_SENT_IND:     /* Subscription message sent */
        {
            callHsEventLog(" HS_VOIP_SUBSCPT_SENT_IND ");
        }
        break;
        case HS_VOIP_NOTIFY_RCVD_IND :
        {
            callHsEventLog(" HS_VOIP_NOTIFY_RCVD_IND");
            debugf("callHsEventHandler: Stack id %x got HS_VOIP_NOTIFY_RCVD_IND\n", callId );
            /* no event data */
        }
        break;
        case    HS_VOIP_NOTIFY_TERM_IND:/* Terminal Notify received (subscription terminated)*/
        {
            callHsEventLog(" HS_VOIP_NOTIFY_TERM_IND ");
        }
        break;
        case HS_VOIP_MSG_WAIT_IND:         /* Message waiting */
        {
            callHsEventLog(" HS_VOIP_MSG_WAIT_IND ");
            debugf("MWI with subid->%d new mesgs->%d old_msgs->%d"
                   "new_urg_msgs-> %d old_urg_msgs-> %d msg status->%s"
                   "msg account->%s msg_class->%s\n ",
                   msg->event_info.msg_wait_ind.sub_id,
                   msg->event_info.msg_wait_ind.new_msgs,
                   msg->event_info.msg_wait_ind.old_msgs,
                   msg->event_info.msg_wait_ind.new_urg_msgs,
                   msg->event_info.msg_wait_ind.old_urg_msgs,
                   msg->event_info.msg_wait_ind.msg_status,
                   msg->event_info.msg_wait_ind.msg_acct,
                   msg->event_info.msg_wait_ind.msg_class);
            callCtrlVoiceMailWaitingSet(
                    msg->event_info.msg_wait_ind.new_msgs,
                    msg->event_info.msg_wait_ind.old_msgs,
                    msg->event_info.msg_wait_ind.new_urg_msgs,
                    msg->event_info.msg_wait_ind.old_urg_msgs
                    );
        }
        break;
        case HS_VOIP_OUTGOING_CALL_REJECTED_IND:/* Outgoing call screened/rejected */
        {
            callHsEventLog(" HS_VOIP_OUTGOING_CALL_REJECTED_IND ");
        }
        break;
        case HS_VOIP_INCOMING_CALL_REJECTED_IND:/* Incoming call screened/rejected */
        {
            callHsEventLog(" HS_VOIP_INCOMING_CALL_REJECTED_IND ");
        }
        break;
        case HS_VOIP_INFO_REQ_RECVD_IND:   /* INFO request received */
        {
            callHsEventLog(" HS_VOIP_INFO_REQ_RECVD_IND ");
        }
        break;
        case HS_VOIP_INFO_RESP:            /* Response for INFO request */
        {
            callHsEventLog(" HS_VOIP_INFO_RESP ");
        }
        break;
        case HS_VOIP_SERVICE_INFO_SENT_IND:/* Service message sent */
        {
            callHsEventLog(" HS_VOIP_SERVICE_INFO_SENT_IND ");
        }
        break;
        case HS_VOIP_SERVICE_REQUEST_IND:  /* Service request received */
        {
            callHsEventLog(" HS_VOIP_SERVICE_REQUEST_IND ");
        }
        break;
        case HS_VOIP_SERVICE_RESPONSE_IND: /* Response for service received */
        {
            callHsEventLog(" HS_VOIP_SERVICE_RESPONSE_IND ");
        }
        break;
        case HS_VOIP_CALL_FORWARD_REQ_IND: /* Request to forward current call, by remote end */
        {
            callHsEventLog(" HS_VOIP_CALL_FORWARD_REQ_IND ");
        }
        break;
        case HS_VOIP_INCOMING_CALL_REDIRECTED_IND:/* Incoming call being redirected to other UA */
        {
            callHsEventLog(" HS_VOIP_INCOMING_CALL_REDIRECTED_IND ");
        }
        break;
        case HS_VOIP_REQ_RETRY_RCVD_IND:/* Request retry response received */
        {
            callHsEventLog(" HS_VOIP_REQ_RETRY_RCVD_IND ");
        }
        break;
        case HS_VOIP_MWI_SUBSCB_RESP_IND:  /* Response for MWI subscription */
        {
            callHsEventLog(" HS_VOIP_MWI_SUBSCB_RESP_IND ");
        }
        break;

        case HS_VOIP_INCOMING_CALL_MVQ_IND:
        {
            //answer
            if(callCtrlIsMvqMode())
            {
               hs_voip_incoming_call_ind_t *data =
                  &msg->event_info.incoming_call_ind;
               
               printf("====>Answer call...\n");
               callCtrlAcceptCallBySlot(data->replaces_callid, 0);
            }
            break;
        }

        // by NOT providing a default, we learn from compiler if we are
        // missing anything...
    }



}

// To avoid possible race conditions? ? ? this is called from
// callHsHelper only when hs software is partly up...
void callHsEventInit(void)
{
    eventlogLogMsg("callHsEventInit called from hs init");
    debugf("callHsEventInit entry.\n");
    hs_voip_app_register_notification(NULL, callHsEventHandler);
    #if 0       // no ... do this later...
    hs_voip_cm_set_endpoint_user_map(0/*endpoint*/, 
        (void *) callCtrlGetOurPhoneNumber() );
    #endif
}
